package com.controller;

import com.server.HttpServlet;
import com.server.HttpServletRequest;
import com.server.HttpServletResponse;
import com.service.UserService;

/**
 * 用于处理所有的请求
 */
public class IndexController extends HttpServlet {

    public IndexController() {
        System.out.println("IndexController对象创建了。。。");
    }

    //我们service层进行真正的执行业务
    private UserService userService = new UserService();

    /**
     * 如果想要服务器进行管理，需要继承接口，并且实现其方法
     *
     * @param request
     */
    @Override
    public void service(HttpServletRequest request, HttpServletResponse response) {
        System.out.println("test方法执行了。。。。");
        //1、接收请求发送过来的参数（携带的参数）
        String username = request.getParameter("username");
        String pass = request.getParameter("pass");
        //2、负责找真正的业务层干活
        String result = userService.login(username, pass);
        System.out.println(result);
        //执行完业务信息进行响应回
        //如果想要浏览器看到信息，遵序浏览器识别的规则,下面是模拟一些前段的标准响应回去
        response.write("HTTP1.1 200 OK\r\n");
        response.write("Content-Type: text/html;charset=UTF-8\r\n");
        response.write("\r\n");
        response.write("<html>");
        response.write("<body>");
        response.write("<input type='button' value='按钮'>");
        response.write("</body>");
        response.write("</html>");
    }
}
